package enemies.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import enemies.constants.ResponseStatusEnum;
import enemies.dao.IMongoCommonDao;
import enemies.dao.UserDao;
import enemies.model.ResponseResult;
import entity.Student;
import entity.UserEntity;

@Controller
@RequestMapping("mongodb")
public class EdithController {
	@Autowired
	private MongoOperations mongoOperations;
	 @Autowired
	    private IMongoCommonDao mongoCommonDao;
	 @Autowired
		private UserDao userDao;
	@ResponseBody
	@RequestMapping("/helloWorld")
	public String helloWorld(){
		return "hello world" ;
	}
	
	 @RequestMapping("/addStudent")
	    @ResponseBody
	    public String addStudent(){
	         Student student = new Student("路绍磊",18);
	         mongoOperations.save(student);
	         return "SUCCEED";
	    }
	 
	 
	 @RequestMapping("/addUser")
	    @ResponseBody
	    public String addUser(){
		 UserEntity user = new UserEntity();
			user.setId(88L);
			user.setUserName("XiaoMing");
			user.setPassWord("123456");
			userDao.saveUser(user);
			 return "SUCCEED";
	    }
	 
	
	 
	 @RequestMapping(value = "/addone", method = RequestMethod.GET)
	    public ResponseResult<String> testMongo()
	    {
	        ResponseResult<String> result = new ResponseResult<>();
	        try
	        {
	            mongoCommonDao.saveDataToMongoDB("just_for_test", null);
	            result.setMessage("成功测试链接mongodb");
	            result.setStatus(ResponseStatusEnum.SUCCESS);
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	        return result;
	    }


}
